import React from "react";
import {connect} from "react-redux";
import {login} from "./Auth.redux";
import {Redirect} from "react-router-dom";

/**
 * 复杂多个reducer时需要用combineReducer合并
 * @returns {*}
 * @constructor
 */
@connect(
    state => state,
    {login}
)
class Auth extends React.Component{
    render(){
        const redirectToDashboard = (<Redirect to="/dashboard"/>);
        const loginBtn = <button onClick={this.props.login}>登录</button>;
        return (
            <div>
                {this.props.auth.isAuth?redirectToDashboard:loginBtn}
                <h2>你没有权限，请先登录</h2>
            </div>);
    }
}
export default Auth;